package com.study.创造型模式.原型模式.深拷贝;

public class Client {

    public static void main(String[] args) throws CloneNotSupportedException {

        DeepProtoType p = new DeepProtoType();
        p.name = "傻逼";
        p.deepCloneableTarget = new DeepCloneableTarget("龙弟","天天装逼");

//        //方式1  完成深拷贝  (如果类中的引用类型属性多的话，需要一个一个去处理，比较麻烦)
//        DeepProtoType p2 = (DeepProtoType) p.clone();
//        System.out.println("p.name="+p.name +"p.DeepCloneableTarget=" +p.deepCloneableTarget.hashCode());
//        System.out.println("p2.name="+p2.name +"p2.DeepCloneableTarget=" +p2.deepCloneableTarget.hashCode());


        //方式2 完成深拷贝     （通过序列化动态的完成深拷贝）
        DeepProtoType p2 = (DeepProtoType) p.deepClone();
        System.out.println("p.name="+p.name +"p.DeepCloneableTarget=" +p.deepCloneableTarget.hashCode());
        System.out.println("p2.name="+p2.name +"p2.DeepCloneableTarget=" +p2.deepCloneableTarget.hashCode());
    }
}
